//
//  ZTSearchListTableViewController.m
//  app001
//
//  Created by xionghao on 15/10/10.
//  Copyright © 2015年 xionghao. All rights reserved.
//

#import "ZTSearchListTableViewController.h"
#import "AttenZTTableViewCell.h"
#import "GMDCircleLoader.h"
#import "SearchMode.h"
#import "MyZTTableViewController.h"
#import <UIImageView+WebCache.h>

@interface ZTSearchListTableViewController ()

@end

@implementation ZTSearchListTableViewController
+(instancetype)viewcontroller{
    ZTSearchListTableViewController *svc=[[ZTSearchListTableViewController alloc]initWithStyle:UITableViewStylePlain];
    return svc;
}




-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}
     ];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbg"] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setTranslucent:YES];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [GMDCircleLoader hideFromView:self.navigationController.view animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden=NO;
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    self.navigationItem.title=@"展厅列表";
    if (self.cond) {
        [GMDCircleLoader setOnView:self.navigationController.view withTitle:@"加载中..." animated:YES];
        NSMutableDictionary *params=[NSMutableDictionary dictionary];
        
        params[@"cond"]=self.cond;
        params[@"action"]=@"s_ting";
        params[@"s_action"]=@"count";
        
        [PostUitls Post:searchurl parameters:params success:^(id response) {
            
            [SearchMode setupReplacedKeyFromPropertyName:^NSDictionary *{
                return @{
                         @"ID":@"id"
                         };
            }];
            NSDictionary *dict=response;
            NSNumber *state=dict[@"state"];
            if ([state integerValue]==400) {
                NSArray *array=    [SearchMode objectArrayWithKeyValuesArray:dict[@"data"]];
                
                self.datalist=array;
                [GMDCircleLoader hideFromView:self.navigationController.view animated:YES];
                [self.tableView reloadData];
            }
            
            
        } failure:^(NSError *error) {
            
        }];

    }else{
        
    }
    self.tableView.rowHeight=80;
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    if (self.datalist.count>0) {
        tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    }else{
        tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    }
    return self.datalist.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    AttenZTTableViewCell *cell = [AttenZTTableViewCell cellWithTableView:tableView];
    SearchMode *mode=self.datalist[indexPath.row];
    cell.titlelabel.text=mode.truename;
    cell.addresslable.text=mode.area_name;
    cell.isShowAdress=YES;
    cell.msglable.text=mode.display_msg;
    cell.accessoryType=UITableViewCellAccessoryNone;
    
    [cell.icon sd_setImageWithURL:[NSURL URLWithString:[NSString getImageURLstr:mode.ico]] placeholderImage:[UIImage imageNamed:@"usericon_placehoder"]];
    // Configure the cell...
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SearchMode *mode=self.datalist[indexPath.row];
    MyZTTableViewController *vc=[MyZTTableViewController viewcontroller];
    vc.user_id=mode.user_id;
    vc.com_id=mode.com_id;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
